<template>
	<view class="page-container">
		<!-- 顶部导航栏 -->
		<view class="header">
			<x-status-bar></x-status-bar>
			<view class="flex-center-between header-navbar">
				<view></view>
				<view class="search-container flex-center" style="margin: 0 16rpx;width: 100%;"
					@click="jumpUrl('/pages/user/shop/search/index/index')">
					<image src="@/static/image/common/search.png" style="width: 32rpx; height: 32rpx"
						class="clear-flex u-m-r-14"></image>
					<view class="color-grew linecamp-1">{{ lang_shop.searchTips }}</view>
				</view>
				<view class="clear-flex inecamp-1">{{ lang_common.search }}</view>
			</view>

			<!-- 余额卡 -->
			<view style="padding: 0 30rpx;">
				<view class="shop-header">
					<image src="@/static/image/shop/shop_header.png" class="shop-header-bg"></image>

					<view class="flex-center" style="padding: 28rpx 0 0 18rpx;">
						<view class="u-avatar-66" style="border: 2rpx solid #FFFFFF;">
							<x-image :src="showImage(userInfo.avatar, 'logo')"/>
						</view>

						<view class="u-m-l-18">
							<view class="u-f-30 u-lh-42 font-medio">{{ userInfo.nick || '' }}</view>
							<view class="u-m-t-2 flex-center u-f-24 u-lh-34">
								<view class="flex-center">
									<view>{{ lang_personal.balance }}:</view>
									<view class="u-m-l-10 font-bold">{{ lang_unit.money }}{{ balance || 0 }}</view>
								</view>
								<view class="u-m-l-26 flex-center">
									<view>{{ lang_personal.score }}:</view>
									<view class="u-m-l-10 font-bold">{{ integral || 0 }}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>

			<view>
				<v-tabs v-model="tabIndex" :tabs="tabList" activeColor="#333333" lineBottom="12"></v-tabs>
			</view>
			<!-- 分割线 -->
			<u-gap height="1" bgColor="rgba(0, 0, 0, 0.07)"></u-gap>
		</view>
		<!-- 列表 -->
		<swiper style="height: calc(100vh - 338rpx - var(--status-bar-height));" :current="tabIndex"
			@change="tabIndex = $event.detail.current">
			<swiper-item v-for="(item, index) in tabs" :key="index">
				<shop-list ref="mescrollItem" :i="index" :index="tabIndex" :category-id="item.categoryId"></shop-list>
			</swiper-item>
		</swiper>
		
		<!-- 购物车按钮 -->
		<view class="cart-btn">
			<image src="@/static/image/index/cart.png" style="width: 126rpx; height: 126rpx"
				@click="jumpUrl('/pages/user/shop/cart/cart')"></image>
				
			<view v-if="cartCount" class="cart-btn-count u-f-20 u-lh-28 font-bold flex-center-center">{{ cartCount || 0 }}</view>
		</view>
	</view>
</template>

<script>
	import ShopList from './components/shop-list.vue'
	export default {
		components: {
			ShopList
		},
		data() {
			// 初始化顶部导航栏
			return {
				tabIndex: 0,
				tabValue: 'all',

				dataList: []
			}
		},
		computed: {
			commodityCategory() {
				return this.$store.state.common.commodityCategory || []
			},
			tabs() {
				let list = [{
					key: 'all',
					label: '全部',
					title: this.lang_common.all
				}]
				return [...list, ...this.commodityCategory]
			},
			tabList() {
				return this.tabs.map(item => item.title)
			}
		},
		onShow() {
			// 初始化分类列表
			this.$store.dispatch('initCategory', 2)
		},
		onLoad() {
			let timer = setTimeout(() => {
				clearTimeout(timer)
				this.$store.commit('UPDATE_TABBAR_VISIBLE_TYPE', 'user')
			}, 100)
		},
		methods: {

		}
	}
</script>

<style scoped lang="scss">
	.search-container {
		width: 100%;
		padding: 16rpx 30rpx;
		border-radius: 100rpx;
		background-color: #F6F6F6;
	}

	.shop-header {
		position: relative;
		top: 0;
		left: 0;
		width: 100%;
		height: 142rpx;
		overflow: hidden;
		color: #FFFFFF;

		&-bg {
			position: absolute;
			top: 0;
			left: 0;
			z-index: -1;
			width: 690rpx;
			height: 142rpx;
		}
	}
	
	.cart-btn {
		position: fixed;
		bottom: 200rpx;
		right: 12rpx;
		z-index: 999999;
		
		&-count {
			position: absolute;
			top: 4rpx;
			right: 8rpx;
			width: 32rpx;
			height: 32rpx;
			color: #FC2642;
			background: #FFFFFF;
			border: 2rpx solid #FC2642;
			border-radius: 100rpx;
		}
	}
</style>
